<?php
/*
** @introduction: 分销提成
** @author: 林小平
** @date: 2016-05-13 11:22
** @email: linxiaoping@cdlinglu.com
*/

namespace Admin\Controller\Distribution;
use Common\Controller\Admin\CommonController;
use Common\Model;

class IndexController extends CommonController{
    /*
    ** @introduction: 分销提成配置
    ** @author: 林小平
    ** @date: 2016-05-13 11:22
    ** @email: linxiaoping@cdlinglu.com
    */
    public function configure(){
        $model = new Model\ConfigureModel();
        $info = $model->getOne();
        $this->assign('info',$info);
        $this->display();
    }
    /*
    ** @introduction: 分销提成添加修改提交
    ** @author: 林小平
    ** @date: 2016-05-13 11:22
    ** @email: linxiaoping@cdlinglu.com
    */
    public function update(){

        $model = new Model\ConfigureModel();
        $result = $model->update($_POST['data']);
        if($result){
            $this->ajaxReturn(['code' => 200, 'msg' => '保存成功']);
        }else{
            $this->ajaxReturn(['code' => 300, 'msg' => '保存失败']);
        }

    }

    /*
    ** @introduction: 佣金列表
    ** @author: 林小平
    ** @date: 2016-05-13 11:22
    ** @email: linxiaoping@cdlinglu.com
    */

    public function lists(){
        $model = D('Common/commission', 'Logic');

        $this->page = I('param.page',1);

        $this->user_id = I('param.user_id',0);

        $this->nums = 20;

        if($this->user_id){
            $where = "user_id=$this->user_id";
        }else{
            $where = "1=1";
        }
        $data = $model->getData($where,$this->page);

        $this->total = $data['total'];

        $this->data = $data['data'];



//        echo '<pre>';
//
//        var_dump($data);
//
//        var_dump($this->data);
//
//        exit;
        $this->display();
    }

}